﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace com.iot.core.data
{
    public partial interface IRepository<TEntity> where TEntity : BaseEntity
    {
        IotDbContext DB { get; }    
        IQueryable<TEntity> GetAll(bool includeDeleted=false);
        Task<int> SaveChagnesAsync();
        int SaveChagnes();

        TEntity GetById(long id);
        Task<TEntity> GetByIdAsync(long id);
        TEntity GetById(BaseQto qm);



        List<TEntity> GetByIds(List<long> lid);
        Task<List<TEntity>> GetByIdsAsync(List<long> lid);


        void Insert(TEntity entity,bool autoField=true);

        void Update(TEntity entity, bool autoField = true);

        void Delete(TEntity entity, bool autoField = true);
        void Detach(TEntity entity );

        List<T> QueryToList<T>(string sql, int CommandTimeout = 30) where T : new();
        List<IdNameDto> QueryName(List<long> lid, string tbname = "", string namefiled = "");
        string GetName(long id, string tbname = "", string namefiled = "");

        void EntityToDto(object src,object dst);
        void DtoToEntity(object src, object dst);

        IQueryable<TEntity> Sort(IQueryable<TEntity> q, Sort sort);

        Page<TEntity> Page(IQueryable<TEntity> q, BasePageQto qm);
        Task<Page<TEntity>> PageAsync(IQueryable<TEntity> q, BasePageQto qm);
    }
}
